package com.mcxx.modules.system.service.read;

import com.mcxx.common.exception.BizException;
import com.mcxx.modules.base.utils.QueryParamUtil;
import com.mcxx.modules.statistics.entity.StatisticsExportEntity;
import com.mcxx.modules.system.dao.read.StatisticsExportReadDao;
import com.mcxx.modules.system.dto.PolicyDTO;
import com.mcxx.modules.system.param.StatisticsExportParam;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yinhai.ta404.core.restservice.resultbean.Page;

import java.util.List;


@Service
@TaTransactional(readOnly = true)
public class StatisticsExportReadService {

    @Autowired
    private StatisticsExportReadDao statisticsExportReadDao;


    public Page getPage(StatisticsExportParam statisticsExportParam, PageParam pageParam, UserAccountVo userAccountVo){
        QueryParamUtil.setBaseParamValue(statisticsExportParam,userAccountVo);
        statisticsExportReadDao.beginPager(pageParam);
        List<StatisticsExportEntity> list = statisticsExportReadDao.getStatisticsList(statisticsExportParam);
        return statisticsExportReadDao.endPager(list);
    }


    public void verifyStatus(List<String> idList, List<String> statusList){

        int cnt = statisticsExportReadDao.countByIdsAndStatus(idList, statusList);


        if(idList.size() != cnt){
            throw new BizException("-1", "当前确认批次中存在状态不正确的，无法进行当前操作");
        }
    }

    public StatisticsExportEntity selectRepeatByAreaCode(String areaCode,String objectType,String years){
        return statisticsExportReadDao.selectRepeatByAreaCode(areaCode,objectType,years);
    }


    public StatisticsExportEntity getByYearATypeACode(StatisticsExportEntity entity){
        return statisticsExportReadDao.getByYearATypeACode(entity);
    }


    public StatisticsExportEntity getById(String id){
        return statisticsExportReadDao.getById(id);
    }

}
